package com.xyzq.hs.util;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.net.URL;
import java.net.URLDecoder;
import java.util.Properties;


public class ConfigUtils {
	private static final String CONFIG_FILE_NAME="config.properties";
	private static Properties prop=null;
	static{
		prop=new Properties();
		try {
			URL url = ConfigUtils.class.getClassLoader().getResource(CONFIG_FILE_NAME);
			String path = url.getPath();
			String filePath=URLDecoder.decode(path,"UTF-8");
			InputStream in=new FileInputStream(filePath);
			prop.load(in);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static String get(String propertyName){
		return get(propertyName,null);
	}
	
	public static String get(String propertyName,String defaultValue){
		return prop.getProperty(propertyName,defaultValue);
	}
	
	public static int getInt(String propertyName){
		return new BigDecimal(get(propertyName)).intValue();
	}
	
	public static void main(String[] args) {
		System.out.println(get("server.url"));
		System.out.println(get("server.port"));
	}
}
